<?php
require_once("globalisempty.php");

if($sysact == "imageUp")
{
	// 上传图片框中的描述表单名称，
	$title = htmlspecialchars($_POST['pictitle'], ENT_QUOTES);
	$path = htmlspecialchars($_POST['dir'], ENT_QUOTES);      

	
		//$file=$_FILES["upfiledata"];
		$upload_name = "upfiledata";
		$imgpath="upfiles/";
		$dir_file=date("Ym");  //获取当前时间
		$dir_file_d=date("d");  //获取当前时间
		$save_path = getcwd() .'/'.$imgpath.$dir_file.'/'.$dir_file_d.'/';$save_path_data = $imgpath.$dir_file.'/'.$dir_file_d.'/';
	
		$fileName = $UP->up($upload_name,$system_time."_".rander());
		
		$thumbfile = $GD->thumb($save_path.$fileName);
		if($sysgroupid)
		{
			$picsize = picsize($sysgroupid);
			$markfile = $GD->mark($save_path.$fileName,$picsize["width"],$picsize["height"]);
		}
		else
		{
			$markfile = $GD->mark($save_path.$fileName);
		}
	
	
		$tmpname = $UP->name($upload_name);#[客户端文件名]
		
		$filetype_array = explode(".",$fileName);
		$filetype_count = count($filetype_array);
		$filetype = strtolower($filetype_array[$filetype_count-1]);
		$tmarr = explode(".",$tmpname);
		$tmpname = $tmarr[0].".".strtolower($tmarr[1]);
		
		$sql = "INSERT INTO ".$prefix."upfiles(filetype,tmpname,filename,folder,postdate,thumbfile,markfile) VALUES('".$filetype."','".$tmpname."','".$fileName."','".$save_path_data."','".$system_time."','".$thumbfile."','".$markfile."')";
		
		$insert_id = $DB->qgInsert($sql);
		unset($sql);


		$return_data['url'] = $imgpath.$dir_file.'/'.$dir_file_d.'/'.$fileName;
		$return_data['title'] = $fileName;
		$return_data['uid'] = $insert_id;
		$return_data['original'] = $_FILES["upfiledata"]["name"];
		$return_data['state'] = "SUCCESS";
		echo json_encode($return_data);
		exit();
		//$this->ajaxReturn($return_data,'json');
}
elseif($sysact == "delgoodimages")
{
	//清msg
	$DB->qgQuery("DELETE FROM ".$prefix."msg WHERE additionid!=0 and thumb='".$thumbid."'");#[删除主题]
	//清图片实际路径
	$msgpic = $DB->qgGetOne("SELECT * FROM ".$prefix."upfiles WHERE id='".$thumbid."'");
	$FS->qgDelete($msgpic["folder"].$msgpic["thumbfile"]);
	$FS->qgDelete($msgpic["folder"].$msgpic["markfile"]);
	$FS->qgDelete($msgpic["folder"].$msgpic["filename"]);
	//清upfiles
	$DB->qgQuery("DELETE FROM ".$prefix."upfiles WHERE id='".$thumbid."'");
	
}
else
{
	
	$info = array(
		'num'=> $num,
		'title' => '',       	
		//'upload' =>U('Admin/Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
		'upload' =>$mainlink."?file=uploadify&act=imageUp&savepath=".$path."&pictitle=banner&dir=images&sysgroupid=".$sysgroupid,
		'size' => '4M',
		'type' =>'jpg,png,gif,jpeg',
		'input' => $input,
		'func' => empty($func) ? 'undefined' : $func,
	);
	Foot("uploadify.qg");
}



?>